package com.example.myweb.Domain.Entity;

import com.example.myweb.Domain.Entity.Article;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = true)
public class ArticleStatusConverter implements AttributeConverter<Article.ArticleStatus, String> {

    @Override
    public String convertToDatabaseColumn(Article.ArticleStatus attribute) {
        // 保存时统一存为大写
        return (attribute == null) ? null : attribute.name();
    }

    @Override
    public Article.ArticleStatus convertToEntityAttribute(String dbData) {
        // 读取时，先转大写再匹配枚举
        if (dbData == null || dbData.trim().isEmpty()) {
            return null;
        }
        return Article.ArticleStatus.valueOf(dbData.toUpperCase());
    }
}